﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Soft.Service
{
    /// <summary>
    /// 方法签名 (唯一标识一个方法)
    /// </summary>
  	public struct FunctionSign : IComparer<FunctionSign>
    {
        public FunctionSign(string fullCode)
        {
            FunctionCode functionCode = FunctionCode.Parse(fullCode);
            this.InstanceName = functionCode.InstanceName;
            this.Code = functionCode.Code;
        }

        public FunctionSign(string sign, string code)
        {
            this.InstanceName = sign;
            this.Code = code;
        }

        public string FullCode
        {
            get
            {
                return this.ToString();
            }
        }


        public bool IsDefaultInstanceName
        {
            get
            {
                return string.IsNullOrWhiteSpace(this.InstanceName);
            }
        }

        public int Compare(FunctionSign x, FunctionSign y)
        {
            return string.Compare(x.Code, y.Code, true);
        }

        public override string ToString()
        {
            if (string.IsNullOrWhiteSpace(this.InstanceName))
            {
                return this.Code;
            }
            return this.InstanceName + "." + this.Code;
        }

        public string InstanceName;

        public string Code;
    }
}
